#ifndef INC_GAME_H
#define INC_GAME_H

#include <irrlicht.h>
#include <iostream>
#include </home/marrabld/Programing/Projects/spellparser/include/irrKlang.h>
#include "/home/marrabld/Programing/pal/pal/pal/palFactory.h"

 typedef enum  {LOADING, 
    		DOUBLE_PEND,
    		STAGE_ONE,
		DONE} gameState;

using namespace irr;
using namespace std;
using namespace irrklang;
namespace videoGame
{

class gameEngine : public IEventReceiver//: public GameEntity
{
public:



gameEngine(bool fullscreen, bool music, bool shadows, bool additive, bool vsync, video::E_DRIVER_TYPE driver);

    ~gameEngine();
    gameState run();
    gameState loadScreen();
    void shoot();
    virtual bool OnEvent(const SEvent& event);
    scene::ISceneManager* sm;
    int BULLET_MAX_SIZE;//these should be in accessor mehtods
    int BULLET_ID;
    int ENEMY_ID;
	gameState returnType;

    struct PointMass
	{
            scene::ISceneNode* node;
            float mass;
            core::vector3df velocity;
            core::vector3df acceleration;
            core::vector3df force;
            core::vector3df MapCollisionPoint;
            core::vector3df direction;
            //constructor
            PointMass()
            {
                velocity = core::vector3df(10,0,0);
            }

	} bullet[50];

	struct Enemy
	{
	    scene::IAnimatedMeshSceneNode* anms;

	     float mass;
	     scene::ISceneNode* node;
            core::vector3df velocity;
            core::vector3df acceleration;
            core::vector3df force;
            core::vector3df MapCollisionPoint;
	} enemy[5];

    private:

    	bool collision(scene::ISceneNode* one, scene::ISceneNode* two, int size);
    	int ScreenResolution_x;// = 800;
	int ScreenResolution_y;// = 600;
	int BitDepth;// = 16;
    	int GAME_RUN;// = 0;

    	ISoundEngine* engine;

    	void Explode(gameEngine::PointMass  bullet);
    	void fire();
	void createLoadingScreen();
	void loadSceneData();
	void switchToNextScene();
	void CreateEnemy();
    	scene::ISceneNode* node;
    	scene::ISceneNode* selectedSceneNode;
	scene::ISceneNode* lastSelectedSceneNode;
    	SKeyMap keyMap[8];

	bool fullscreen;
	bool music;
	bool shadows;
	bool additive;
	bool vsync;
	bool DEBUG;
	video::E_DRIVER_TYPE driverType;
	IrrlichtDevice *device;

	struct SParticleImpact
	{
		u32 when;
		core::vector3df pos;
		core::vector3df outVector;
	};

	int currentScene;
	video::SColor backColor;

	gui::IGUIStaticText* statusText;
	gui::IGUIInOutFader* inOutFader;

	scene::IQ3LevelMesh* quakeLevelMesh;
	scene::ISceneNode* quakeLevelNode;
	scene::ISceneNode* skyboxNode;
	scene::IAnimatedMeshSceneNode* model1;
	scene::IAnimatedMeshSceneNode* model2;
	scene::IParticleSystemSceneNode* campFire;
	scene::ICameraSceneNode* camera;
	scene::IMetaTriangleSelector* metaSelector;
	scene::ITriangleSelector* mapSelector;

	s32 sceneStartTime;
	s32 timeForThisScene;

	core::array<SParticleImpact> Impacts;
};

class CIrrTimer
   {
     public:
            IrrlichtDevice * m_device;

            CIrrTimer() {};
            CIrrTimer(IrrlichtDevice * device)
                {

                        m_device=device;
                        Reset();
                };

            int m_Time;
            int m_DeltaTime;
            irr::f32 m_TimeFactor;

            void Reset()
                {
                        m_Time = m_device->getTimer()->getTime();
                };

            void Update()
                {
                        m_DeltaTime = m_device->getTimer()->getTime() - m_Time;
                        m_Time += m_DeltaTime;
                        m_TimeFactor = m_DeltaTime * 0.001f;
                };
    };

class BindObject {
public:
   //the Irrlicht Node
   irr::scene::ISceneNode *node;
   //the PAL "Node"
   palBodyBase *pb;
   //update Irrlicht position from physics
   void Update() {
      //get the location matrix from the physics system
      palMatrix4x4 matrix = pb->GetLocationMatrix();
      //copy it to a Irrlicht matrix
      core::matrix4 mat;
      memcpy(&mat[0], matrix._mat, sizeof(f32)*4*4);
      //set the node position from our Irrlicht matrix
      node->setPosition(mat.getTranslation());
      node->setRotation(mat.getRotationDegrees());
   }
};



};
#endif // INC_GAME_H
